/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: hp
 * Date: 2024-02-27
 * Time: 22:30
 */

public class Student {
    private String name;
    private int age;
    private String gender;
    //没有被static修饰的变量叫做实例变量
    private static String classRoom = "bit";

    public String getName() {
        return this.name;
    }

    public void setName(String name) {
        this.name = name;
    }

    /*public String getName() {
        return this.name;
    }

    public void setName(String name) {
        this.name = name;
    }*/

    //构造代码块（也是实例代码块）
    //初始化实例对象
    {
        this.name = "bit";
        this.age = 18;
        this.gender = "female";
        System.out.println("这是实例代码块!");
    }

    //用静态代码块初始化静态成员变量
    //无论生成多少个对象，静态代码块都只执行一次
    //多个静态代码块会合并再按照先后顺序进行执行
    static {
        classRoom = "bit112";
        System.out.println("这是静态代码块!");
    }
    static {
        System.out.println("chongfu1");
    }
    static {
        System.out.println("choufuer");
    }

    //静态变量需要用静态的方法来访问
    //被static修饰的成员方法会直接变成静态成员方法，就是类方法不再属于某个对象所特有的方法了.

    /*public String name;
    public int age;
    public String gender;
    public static String classRoom = "bit";*/

    public static String classRoom() {
        //age +=1;
        //这里要清楚的时静态方法中不能访问非静态的成员变量
        return classRoom;
    }

    public Student() {
        System.out.println("这是空参");
    }

    public Student(String name, int age, String gender) {
        this.name = name;
        this.age = age;
        this.gender = gender;
    }



    /*public Student() {

    }

    public Student(String name,int age) {
        this.name = name;
        this.age = age;
    }*/

    public void doHome() {
        System.out.println(this.name + "在写作业");
    }

    public void show() {
        System.out.println(" 姓名: " + this.name + " 年龄：" + this.age);
    }



    /*public static void main2(String[] args) {
        Student s1 = new Student();
        *//*Student s2 = new Student();
        Student s3 = new Student();*//*
        s1.show();
        //先执行静态代码块并且只执行一次
        //在执行实例代码块也就时构造代码块 (实例代码块只有在对象创建时执行)
        //最后在进行参数的方法
    }*/

    /*public static void main1(String[] args) {
        Student student = new Student();
        student.name = "zhangsan";
        student.age = 18;
        student.show();
    }*/

    public static void func() {
        System.out.println("直接访问");
/*        System.out.println(this.name+"xxxx");*/
        //在静态方法中不能调用非静态成员变量和成员方法
    }



}
